home *** CD-ROM | disk | FTP | other *** search
/ Mac Magazin/MacEasy 37 / Mac Magazin and MacEasy Magazine CD - Issue 37.iso / Software / Grafik / Web-Publishing / FixPageMill 1.3 ƒ / FixPageMill 1.3.txt < prev    next >
Text File  |  1996-03-27  |  8KB  |  317 lines

  1. (* Adobe's PageMill 1.0 is a nearly-great application for quickly and efficiently
  2. creating World Wide Web pages which look good in common browsers such as Netscape.
  3. It is only *nearly*-great, however, since it makes its own set of assumptions
  4. and some down-right mistakes in HTML code. The following script will open PageMill
  5. documents using BBEdit 3.5 (the commercial version only -- I don't think the Lite
  6. version supports AppleScript).
  7.  
  8. Some of the Find/Replace patterns change true errors in the PageMill code
  9. (significantly, Pattern (10) changes the notorious <BR> <BR> code to the more
  10. standard <P>). However, many of the Find/Replace patterns are cosmetic only,
  11. and do not affect the final HTML code.
  12.  
  13. Important!!!!
  14. Note that if you, for any reason want to keep runs of multiple spaces (say to
  15. preserve whitespace using the <PRE> </PRE> tag), you must comment out the
  16. fourth pattern!
  17.  
  18. The following script is "e-mail-ware." If you like it, send me a friendly message.
  19. if you have suggestions for improvements, I want to hear from you even more!
  20.  
  21. Clint MacDonald <cbbccm2@tthsc6.lubb.ttuhsc.edu>
  22. Cell Biology & Biochemistry
  23. Texas Tech University Health Sciences Center
  24. 3601 4th Street
  25. Lubbock, TX 79430
  26.  
  27. March 27, 1996 *)
  28.  
  29. -- ----------
  30.  
  31. property HTML_File : false
  32. property HTML_File_End : false
  33. global docList
  34.  
  35. -- ----------
  36.  
  37. on run
  38.     tell application "Finder"
  39.         activate
  40.         set docList to selection
  41.     end tell
  42.     tell application "BBEdit 3.5"
  43.         activate
  44.         repeat with i from 1 to (count items in docList)
  45.             open (item i of docList as alias)
  46.             checkHTML() of me
  47.             if HTML_File and HTML_File_End then
  48.                 
  49.                 cleanUpPageMill(docList) of me
  50.                 
  51.             else
  52.                 display dialog "The file " & (item i of docList) & ¬
  53.                     " does not seem to be an HTML file." buttons {"OK"} default button 1
  54.                 tell me to quit
  55.             end if
  56.             
  57.         end repeat
  58.         
  59.         display dialog ¬
  60.             "Would you like to save the changes to all files?" buttons {"Yes", "Later"} default button 2
  61.         if button returned of result is "Yes" then
  62.             repeat with i from 1 to (count of windows)
  63.                 go to line 0
  64.                 tell window i to save
  65.             end repeat
  66.         else
  67.             go to line 0
  68.         end if
  69.         
  70.     end tell -- BBEdit
  71.     
  72.     
  73. end run
  74.  
  75. -- ----------
  76.  
  77. on open (docList)
  78.     tell application "BBEdit 3.5"
  79.         activate
  80.         repeat with i from 1 to (count items in docList)
  81.             open (item i of docList as alias)
  82.             checkHTML() of me
  83.             if HTML_File and HTML_File_End then
  84.                 
  85.                 cleanUpPageMill(docList) of me
  86.                 
  87.             else
  88.                 display dialog "The file " & (item i of docList) & ¬
  89.                     " does not seem to be an HTML file." buttons {"OK"} default button 1
  90.                 tell me to quit
  91.             end if
  92.             
  93.         end repeat
  94.         
  95.         display dialog ¬
  96.             "Would you like to save the changes to all files?" buttons {"Yes", "Later"} default button 2
  97.         if button returned of result is "Yes" then
  98.             repeat with i from 1 to (count of windows)
  99.                 go to line 0
  100.                 tell window i to save
  101.             end repeat
  102.         else
  103.             go to line 0
  104.         end if
  105.         
  106.     end tell -- BBEdit
  107.     
  108. end open
  109.  
  110. -- ----------
  111.  
  112. on cleanUpPageMill(docList)
  113.     
  114.     -- here's the meat of the script!
  115.     -- to omit any individual pattern, comment out its subroutine here
  116.     eraseWhiteSpace() of me
  117.     HRline() of me
  118.     elimDoubleSpace() of me -- comment out if using <PRE></PRE> tags
  119.     spaceBR() of me
  120.     endHeader() of me
  121.     orphaned_P() of me
  122.     addressBR() of me
  123.     double_BR() of me
  124.     eraseNATSIZEFLAG() of me
  125.     isolateHeadBody() of me
  126.     tooManyReturns() of me
  127.     
  128. end cleanUpPageMill
  129.  
  130. -- ----------
  131.  
  132. on checkHTML()
  133.     tell application "BBEdit 3.5"
  134.         
  135.         go to line 0
  136.         find "<HTML>"
  137.         set HTML_File to the result
  138.         find "</HTML>" without grep
  139.         set HTML_File_End to the result
  140.         go to line 0
  141.         
  142.     end tell --BBEdit
  143. end checkHTML
  144.  
  145. -- ----------
  146.  
  147. on eraseWhiteSpace()
  148.     tell application "BBEdit 3.5"
  149.         -- Pattern 1
  150.         -- this grep pattern erases spaces at the end of a line
  151.         -- which PageMill seems to like to include
  152.         replace Every Occurrence searching for "  *$" using "" with grep
  153.     end tell --BBEdit
  154. end eraseWhiteSpace
  155.  
  156. -- ----------
  157.  
  158. on HRline()
  159.     tell application "BBEdit 3.5"
  160.         -- Pattern 2
  161.         -- this Find/Replace (with the one following it) places
  162.         -- the <HR> tag on its own line
  163.         replace Every Occurrence searching for ">
  164. <HR><" using ">
  165. <HR>
  166. <"
  167.         -- ----------
  168.         replace Every Occurrence searching for "<HR>" using "
  169. <HR>
  170. "
  171.     end tell --BBEdit
  172. end HRline
  173.  
  174. -- ----------
  175.  
  176. on elimDoubleSpace()
  177.     tell application "BBEdit 3.5"
  178.         -- Pattern 3
  179.         -- IMPORTANT!
  180.         -- COMMENT THIS PATTERN OUT if you are using the <PRE> </PRE>
  181.         -- tags, or if for any other reason you want to keep multiple spaces
  182.         -- this set of Find/Replaces eliminates two or more spaces
  183.         -- in a row; note the grep pattern in the middle "space-space-space-*"
  184.         -- which will find two or more spaces in a row.
  185.         replace Every Occurrence searching for "    <TITLE>" using "%%%%%<TITLE>"
  186.         replace Every Occurrence searching for "   *" using " " with grep
  187.         replace Every Occurrence searching for "%%%%%<TITLE>" using "    <TITLE>"
  188.     end tell --BBEdit
  189. end elimDoubleSpace
  190.  
  191. -- ----------
  192.  
  193. on spaceBR()
  194.     tell application "BBEdit 3.5"
  195.         -- Pattern 4
  196.         -- cleans up unnecessary spaces after periods
  197.         replace Every Occurrence searching for "  *<BR>
  198. " using "<BR>
  199. " with grep
  200.         -- ----------
  201.         replace Every Occurrence searching for "  *<P>
  202. " using "<P>
  203. " with grep
  204.     end tell --BBEdit
  205. end spaceBR
  206.  
  207. -- ----------
  208.  
  209. on endHeader()
  210.     tell application "BBEdit 3.5"
  211.         -- Pattern 5
  212.         -- PageMill likes to move the ending header tag to a new line
  213.         -- by itself; this grep pattern removes the return character 
  214.         -- preceeding any ending tag
  215.         replace Every Occurrence searching for ">
  216. </H([1-6])>" using "></H\\1>" with grep
  217.     end tell --BBEdit
  218. end endHeader
  219.  
  220. -- ----------
  221.  
  222. on orphaned_P()
  223.     tell application "BBEdit 3.5"
  224.         -- Pattern 6
  225.         -- adds a blank line before orphaned <P> tags
  226.         replace Every Occurrence searching for ">
  227. <P>" using ">
  228.  
  229. <P>"
  230.     end tell --BBEdit
  231. end orphaned_P
  232.  
  233. -- ----------
  234.  
  235. on addressBR()
  236.     tell application "BBEdit 3.5"
  237.         -- Pattern 7
  238.         -- I couldn't make PageMaker place more than one <BR> tag before
  239.         -- an <ADDRESS> tag, so I replace it with a <P>
  240.         replace Every Occurrence searching for "<BR>
  241. <ADDRESS>" using "<P>
  242.  
  243. <ADDRESS>"
  244.     end tell --BBEdit
  245. end addressBR
  246.  
  247. -- ----------
  248.  
  249. on double_BR()
  250.     tell application "BBEdit 3.5"
  251.         -- Pattern 8
  252.         -- this Find/Replace eliminates the dreaded "double-<BR>" tags
  253.         -- which PageMill always inserts instead of the more correct <P>
  254.         replace Every Occurrence searching for "<BR>
  255. <BR>" using "<P>
  256. "
  257.     end tell --BBEdit
  258. end double_BR
  259.  
  260. -- ----------
  261.  
  262. on eraseNATSIZEFLAG()
  263.     
  264.     tell application "BBEdit 3.5"
  265.         -- Pattern 9
  266.         -- eliminates the NATURALSIZEFLAG attribute from <IMG> tags
  267.         replace Every Occurrence searching for " NATURALSIZEFLAG=
  268. \"[0-3]\"" using "" with grep
  269.         replace Every Occurrence searching for "
  270. NATURALSIZEFLAG=\"[0-3]\"" using "" with grep
  271.         replace Every Occurrence searching for " NATURALSIZEFLAG
  272. =\"[0-3]\"" using "" with grep
  273.         replace Every Occurrence searching for " NATURALSIZEFLAG=\"[0-3]\"
  274. " using "" with grep
  275.         replace Every Occurrence searching for " NATURALSIZEFLAG=\"[0-3]\"" using "" with grep
  276.     end tell --BBEdit
  277.     
  278. end eraseNATSIZEFLAG
  279.  
  280. -- ----------
  281.  
  282. on isolateHeadBody()
  283.     tell application "BBEdit 3.5"
  284.         -- Pattern 10
  285.         -- adds a line between the Header and Body sections
  286.         -- adds a line between the last line of the text and the end
  287.         -- of the Body
  288.         replace Every Occurrence searching for "</HEAD>
  289. <BODY(.*)>" using "</HEAD>
  290. <BODY\\1>
  291. " with grep
  292.         -- ----------
  293.         replace Every Occurrence searching for "</BODY>
  294. </HTML>" using "
  295. </BODY>
  296. </HTML>"
  297.     end tell --BBEdit
  298. end isolateHeadBody
  299.  
  300. -- ----------
  301.  
  302. on tooManyReturns()
  303.     
  304.     tell application "BBEdit 3.5"
  305.         -- Pattern 11
  306.         -- eliminates extra returns that might have crept in
  307.         replace Every Occurrence searching for "
  308.  
  309.  
  310.  
  311. *" using "
  312.  
  313. " with grep
  314.     end tell -- BBEdit
  315.     
  316. end tooManyReturns
  317.